<?php
include 'cfg.php';

$stmt = $dbh->prepare('select * from menu',
    array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));

$stmt->execute();

for($i=0; $row = $stmt->fetch(); $i++){
    $menu[]=$row['name'];    
}

$id=isset($_GET['id'])?$_GET['id']:'Home';
$p=isset($_GET['p'])?$_GET['p']:1;
$m=isset($_GET['m'])?$_GET['m']:'Home';

$pagesize = 1;
$pageval = ($p-1)*$pagesize;
$stmt = $dbh->prepare("select * from article order by id desc limit $pageval,$pagesize",
    array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));

$stmt->execute();

for($i=0; $row = $stmt->fetch(); $i++){
    $article[$i]['id']=$row['id'];
    $article[$i]['title']=$row['title'];
    $article[$i]['content']=$row['content'];
    $article[$i]['pubdate']=$row['pubdate'];
}


$stmt = $dbh->prepare("select id, substring(title,1,16) as title from article order by id desc limit 1000",
    array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));

$stmt->execute();

for($i=0; $row = $stmt->fetch(); $i++){
    $article_latest[$i]['id']=$row['id'];
    $article_latest[$i]['title']=$row['title'];
    //$article_latest[$i]['content']=$row['content'];
    //$article_latest[$i]['pubdate']=$row['pubdate'];
}

//print_r($article_latest);

if($id!='Home'){
    
    $stmt = $dbh->prepare("select * from article where id = $id",
        array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
    
    $stmt->execute();
    
    $row = $stmt->fetch();
        $article_one['id']=$row['id'];
        $article_one['title']=$row['title'];
        $article_one['content']=$row['content'];
        $article_one['pubdate']=$row['pubdate'];
    
}

if($m==='About'){
    $include_file = 'input.php';
}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>DarkMatter </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="dark_default.css" rel="stylesheet" type="text/css" />
<link href="" rel="icon" type="image/x-icon" />
<!--<script type="text/javascript" src="http://bfq.cnr.cn/zhibo/flash/swfobject.js"></script>-->
<script language="javascript" type="text/javascript">
var rtmpURLList = ["http://rtmpcnr001.cnr.cn/live/zgzs/playlist.m3u8","http://rtmpcnr002.cnr.cn/live/jjzs/playlist.m3u8","http://rtmpcnr003.cnr.cn/live/yyzs/playlist.m3u8","http://rtmpcnr004.cnr.cn/live/dszs/playlist.m3u8","http://rtmpcnr006.cnr.cn/live/szzs/playlist.m3u8","http://rtmpcnr007.cnr.cn/live/hxzs/playlist.m3u8","http://rtmpcnr008.cnr.cn/live/xgzs/playlist.m3u8","http://rtmpcnr009.cnr.cn/live/mzzs/playlist.m3u8","http://rtmpcnr011.cnr.cn/live/lnzs/playlist.m3u8","http://rtmpcnr013.cnr.cn/live/wygb/playlist.m3u8","http://rtmpcnr012.cnr.cn/live/zygb/playlist.m3u8","http://rtmpcnr014.cnr.cn/live/ylgb/playlist.m3u8","http://rtmpcnr005.cnr.cn/live/zhzs/playlist.m3u8","http://rtmpcnr010.cnr.cn/live/wyzs/playlist.m3u8","http://rtmpcnr019.cnr.cn/live/zhpd/playlist.m3u8","http://rtmpcnr016.cnr.cn/live/gsgljtgb/playlist.m3u8","http://rtmpcnr017.cnr.cn/live/xczs/playlist.m3u8","http://202.177.192.99/live/smil:radio2_aac_1.smil/playlist.m3u8","http://202.177.192.99/live/smil:radio5_aac_1.smil/playlist.m3u8","http://202.177.192.100/live/smil:radio1_aac_1.smil/playlist.m3u8","http://202.177.192.99/live/smil:pth_aac_1.smil/playlist.m3u8","http://202.177.192.99/live/smil:dab35_aac_1.smil/playlist.m3u8","http://202.177.192.100/live/smil:dab33_aac_1.smil/playlist.m3u8","http://202.177.192.98/live/smil:dab31_aac_1.smil/playlist.m3u8","http://202.177.192.98/live/smil:radio3_aac_1.smil/playlist.m3u8","http://202.177.192.100/live/smil:radio4_aac_1.smil/playlist.m3u8",];
var currentTabIndex = 0;
function changeTab1(inderx){
document.getElementById ("audio_play0").style.display  ="block";
//document.getElementById ("img"+inderx).src =arr[inderx];
fBrowserRedirect(inderx);
}
function swfAudioPlayerEmbed(inderx){
swfobject.embedSWF("http://bfq.cnr.cn/zhibo/flash/playerYH.swf",
"player",
"280", "32",
"9.0.28",
"expressInstall.swf",
{
playURL: escape(rtmpURLList[inderx]),
isAutoPlay : true
},
{
allowScriptAccess:"always"
//wmode:"transparent"
});
}
function fBrowserRedirect(inderx){
swfAudioPlayerEmbed(inderx);
}
</script>
</head>
<body>
<div id="header">
  <h1>DarkMatter </h1>
  <h2>Menu</h2>
  <ul>
<?php foreach($menu as $key=>$val):?>
    <li><a<?php if ($val===$m):?> class="active"<?php endif?> href="/?m=<?php echo $val?>"><?php echo $val?></a></li>
<?php endforeach?>

  </ul>
</div>
<div id="content">
  <div id="colTwo">

    <!-- <h2>Welcome</h2>
    <img src="http://templated.co/items/demos/darkened/images/img7.jpg" alt="" width="114" height="104" style="float: left; margin-right: 25px;" /> -->
    
<?php if ('Home'===$m && 'Home'===$id) :?>

    <?php foreach($article as $key=>$val):?>
    <div class="box">
        	<p class="pubdate"><?php echo date("F j, Y, g:i a",$val['pubdate'])?></p>
            <p class="title"><?php echo $val['title']?></p>
    		<?php echo $val['content']?>
    </div><!-- .box -->            
	<?php endforeach?>   

<p class="page_link"><a href="/?p=<?php echo $p+1?>">Next Page</a><br /></p>

<?php endif?>

<?php if ('Home'!=$m) :?>
<?php include $include_file;?>
<?php endif?>

<?php if ('Home'!=$id):?>
    <div class="box">
        <p class="pubdate"><?php echo date("F j, Y, g:i a",$article_one['pubdate'])?></p>
    	<p class="title"><?php echo $article_one['title']?></p>
    	<?php echo $article_one['content']?>
    </div><!-- .box -->      
<?php endif?>
    
    <div class="box">
    <h2>Blandit Etiam</h2>
<!--
<div class="audio_play" id="audio_play0">
    <div class="audio_btn">
        <div id="playerContainer0"><object  id="player" data="http://bfq.cnr.cn/zhibo/flash/playerYH.swf" type="application/x-shockwave-flash" height="32" width="245"><param value="always" name="allowScriptAccess"><param value="playURL=http://rtmpcnr001.cnr.cn/live/zgzs/playlist.m3u8&isAutoPlay=true" name="flashvars"></object></div>
    </div>
    <div class="audio_text"></div>
</div>-->
<script>
//changeTab1(0);
for (var i=0;i<rtmpURLList.length;i++)
{
  document.write ("<a href=\"javascript:changeTab1("+i+");\">"+parseInt(i+1)+"</a> ");
}
</script>
</div><!-- .box -->
    
  </div><!-- #colTow -->

<?php if ('Home'===$m) :?>

    <div id="colOne">
    <h3>Lorem Ipsum</h3>
    <ul class="list">
  <?php if ('Home'===$m):?>
    <?php $n=1?>
    <?php foreach($article_latest as $key=>$val):?>
    	<li><a href="/?id=<?php echo $val['id']?>"><?php echo $val['title']?></a></li>
        <?php if ($n===1000) :?><?php break?><?php endif?><?php $n++?>
    <?php endforeach?>    

  <?php else:?>
    
    <?php foreach($article_latest as $key=>$val):?>
    	<?php if ($val['cate']===$m) :?>
			<li><a href="/?id=<?php echo $val['id']?>"><?php echo $val['title']?></a></li>
		<?php endif?>
	<?php endforeach?>    

  <?php endif?>

    </ul>
    <p>&nbsp;</p><!-- 
    <h3>Consequat Portitor</h3>
    <p><img src="http://templated.co/items/demos/darkened/images/img6.jpg" alt="" width="179" height="59" /></p>
    <p>Vestibulum pellentesque. Morbi sit amet magna ac lacus dapibus interdum. Donec <a href="#">pede nisl gravida</a> iaculis, auctor vitae, bibendum sit amet, mauris. Cras adipiscing libero et risus. Donec rutrum. <a href="#">More&#8230;</a></p>
     -->
  </div><!-- #colOne -->
  
<?php else:?>  
  
<style> #colTwo {width: 680px;} </style>
<?php endif?>

</div><!-- #content -->
<div id="footer">
  <p>Copyright (c) 2006 Sitename.com. All rights reserved. Design by <a href="http://freecsstemplates.org/">Free CSS Templates</a>.</p>
</div>
</body>
</html>
